/*
 * Parcel.java
 *
 * This class calculates the the fare for transporting a parcel depending
 * on the destination distance, and content and weight of the parcel.
 *
 * 
 */

package com.javacore.day8.courier;

import java.util.Scanner;

/**
 * This class encapsulates the information about the content of a parcel
 * and destination of a parcel in two nested classes Content and
 * Destination respectively.
 * @author 
 */

public class Parcel {
    
    /** Creates a new instance of Parcel */
    public Parcel() {
    }
    
    /**
     * This class stores details about the content of the parcel.
     */
    class Content {
        
        /**
         * Instance variable to store weight.
         */
        int weight;
        
        /**
         * Instance variable to store the type of content.
         */
        String contentType;
        
        /**
         * Instance variable to store rate.
         */
        double rate;
        
        /** Creates a new instance of Content */
        public Content() {
            weight = 0;
            contentType = "";
            rate = 0;
        }
        
        /**
         * Method to accept details about the content of the parcel.
         */
        void setContentDetails() {
            Scanner input = new Scanner(System.in);
            
            System.out.println("Enter content type (Food/Cosmetic/Books):");
            contentType = input.next();
            System.out.println("Enter weight(lbs):");
            weight = input.nextInt();
            
            validateContentDetails();
        }
        
        /**
         * Method to check if the information entered by the user is valid.
         */
        private void validateContentDetails() {
            
            if (contentType.equalsIgnoreCase("Food")) {
                if (weight >= 3) {
                    rate = 10;
                } else if (weight < 3 ) {
                    System.out.println("Minimum weight required is 3 lbs. Try again...");
                    setContentDetails();
                }
            }
            
            if (contentType.equalsIgnoreCase("Cosmetic")) {
                if (weight >= 4) {
                    rate = 15;
                } else if (weight < 4) {
                    System.out.println("Minimum weight required is 4 lbs. Try again...");
                    setContentDetails();
                }
            }
            
            if (contentType.equalsIgnoreCase("Books")) {
                if(weight >= 5) {
                    rate = 10;
                } else if(weight < 5) {
                    System.out.println("Minimum weight required is 5 lbs. Try again...");
                    setContentDetails();
                }
            }
        }
        
        /**
         * Method to display the details about the content of the parcel.
         */
        public void getContentDetails() {
            System.out.println("Content type: " + contentType);
            System.out.println("Weight is: " + weight + " lbs");
        }
    }
    
    /**
     * This class stores details about the destination of the parcel
     * and the fare required to send the parcel.
     *
     */
    
    class Destination {
        
        /**
         * Instance variable to store place of delivery.
         */
        String place;
        
        /**
         * Instance variable to store distance in kilometers.
         */
        int kms;
        
        /**
         * Instance variable to store fare.
         */
        int fare;
        
        /** Creates a new instance of Destination */
        public Destination() {
            place = "";
            kms = 0;
            fare = 0;
        }
        
        /**
         * Method to get destination details of the parcel from the user.
         */
        void setDestinationDetails() {
            Scanner input = new Scanner(System.in);
            System.out.println("Enter location:");
            place = input.next();
            System.out.println("Enter kilometers:");
            kms = input.nextInt();
        }
        
        /**
         * Method to display the destination and fare of the parcel.
         * @param rate Parameter containing rate of transporting the parcel
         * @param weight Parameter containing weight of the parcel
         */
        void getDestinationDetails(double rate, int weight) {
            System.out.println("Destination for delivering the Parcel: " + place);
            System.out.println("Fare: $" + kms * rate * (weight * 0.1));
        }
    }
}
